<!--Rise发布-->
<?php
$conn=new mysqli("localhost","root","123456","htmlkeshe");
$conn->query("set names utf8");

$sql="SELECT * FROM news where whichGame='MHR'";
$result=$conn->query($sql);

//跳转页面所需的数据
$totalnum=mysqli_num_rows($result);//总数
$pagesize=5;//每页大小
$page=isset($_GET["page"])?$_GET["page"]:1;//如果传入page则读取第几页否则就是1
$begin=($page-1) * $pagesize;//数据库中字段开始位置 page在此处发生改变 具体页面没变 但是读取的数据改变了
$totalpage=ceil($totalnum/$pagesize);//页数

//所要展示的内容

//读取到我的新闻内容
$sql="SELECT * FROM news  where whichGame='MHR' order by newsId DESC limit $begin,$pagesize";//limit从x开始多少个
$result=$conn->query($sql);
$datanum=mysqli_num_rows($result);

for($i=1;$i<=$datanum;$i++){
    $info=mysqli_fetch_assoc($result);//读取下一条的内容 并且返回数组
    $fp = fopen($info["newsContent"],"r");


    $listOut = <<<EOF
                <div class="news_list">
                    <div id="new1" class="mode">
                        <div class="mode_left">
                        <!--使用大括号获取php中变量-->
                        <a href="./news.php?id={$info['newsId']}">
                            <img src="{$info['newsPic']}"/>
                        </a>
                        </div>
                           
                        <div class="mode_right">
                            <div class="mode_right_inner">
                                <a href="./news.php?id={$info['newsId']}"> <div class="mode_right_inner_title">{$info['title']}</div> </a>
                                <div class="mode_right_inner_footer">  作者:{$info['authorName']} <br/> 发布时间:{$info['newsTime']}<br/>热度:{$info['heat']}</div>
                            </div>
                        </div>
                    </div>
                </div>
EOF;
    echo $listOut;
}
//页面跳转部分
$pageOut="<div class='center_content_footer'>";
if($page>1)
{
    $pageOut.="<span onclick='showNews4($page-1)'> < </span>";
}

if($page<4) {
    for($j=1;$j<$page;$j++){
        $pageOut .= "<span onclick='showNews4($j)'> $j </span>";
    }
    for ($j = $page+1; $j <= min($totalpage, 7);$j++) {
        $pageOut .= "<span onclick='showNews4($j)'> $j </span>";
    }
}
elseif ($page>$totalpage-3)
{
    for($j=$totalpage-6;$j<$page;$j++){
        $pageOut .= "<span onclick='showNews4($j)'> $j </span>";
    }
    for($j = $page+1;$j<=$totalpage;$j++){
        $pageOut .= "<span onclick='showNews4($j)'> $j </span>";
    }
}
else{
    for($j=$page-3;$j<=$page+3;$j++){
        $pageOut .= "<span onclick='showNews4($j)'> $j </span>";
    }
}

if($page<$totalpage)
{
    $pageOut.="<span onclick='showNews4($page+1)'> > </span>";
}

$pageOut.="</div>";
echo $pageOut;
$conn->close();
?>